<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p {
            width: 300px;
            line-height: 30px;
            background-color: lightblue;
            color: red;
        }
    </style>
</head>
<body>
    <button class="btn">显示当前的系统时间</button>
    <p>点击按钮显示时间</p>
    <script>
        var btn = document.querySelector('.btn');
        var p = document.querySelector('p');

        btn.onclick = function(){
            p.innerText = tt;
        }
        function date (t){
            // var t = new Date;
            var Y = t.getFullYear();
            var M = t.getMonth();
            var D = t.getDate();

            var h = t.getHours();
            var m = t.getMinutes();
            var s = t.getSeconds();

            var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            var day = t.getDay();
            //如果月日 时分秒 小于10 就前年加个 0
            M = M < 10 ? '0' + M : M;
            D = D < 10 ? '0' + D : D;
            h = h < 10 ? '0' + h : h;
            m = m < 10 ? '0' + m : m;
            s = s < 10 ? '0' + s : s;

            return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s + ' ' + arr[day];
        }
        var tt = date(new Date());
    </script>
</body>
</html>